﻿// ***********************************************************************
// Assembly         : SgResearch.Core
// Author           : Jean-Francois LEQUEUX
// Created          : 04-13-2013
// Last Modified By : Jean-Francois LEQUEUX
// Last Modified On : 04-13-2013
// ***********************************************************************
// <copyright file="AjaxOnlyAttribute.cs" company="SGCIB">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace MvcToolbox
{
    /// <summary>
    /// Class AjaxOnlyAttribute
    /// </summary>
    public class AjaxOnlyAttribute : ActionMethodSelectorAttribute
    {
        /// <summary>
        /// Determines whether the action method selection is valid for the specified controller context.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="methodInfo">Information about the action method.</param>
        /// <returns>true if the action method selection is valid for the specified controller context; otherwise, false.</returns>
        [ExcludeFromCodeCoverage]
        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
        }
    }
}
